package com.pan;

import com.pan.entity.PosNameMapper;
import com.pan.io.ReadCSV;
import com.pan.mapping.LineToObject;

import java.io.File;
import java.util.List;

public class MyReadCSV<T> {

    private ReadCSV readCSV;
    private LineToObject<T> lineToObject;

    public MyReadCSV(File csvFile, String limiter, Class<T> objClass, List<PosNameMapper> posNameMapperList) {
        readCSV = new ReadCSV(csvFile,limiter);
        lineToObject = new LineToObject<T>(objClass,posNameMapperList);
    }
    public MyReadCSV(File csvFile, Class<T> objClass, List<PosNameMapper> posNameMapperList){
        this(csvFile,",",objClass,posNameMapperList);
    }

    public void skip(){
        if (readCSV.hasNextLine()){
            readCSV.nextLine();
        }
    }
    public T next(){
        String[] lineArr = readCSV.nextLine();
        T object = lineToObject.arrToObject(lineArr);
        return object;
    }


    public boolean hasNext(){
        return readCSV.hasNextLine();
    }

    public void close(){
        readCSV.close();
    }
}
